👀 Reading hidden code
using Pkg
👀 Reading hidden code
Activating project at `~/.julia/environments/v1.7`
The package AbstractPlutoDingetjes.jl could not load because it failed to initialize.
That's not nice! Things you could try:
- Restart the notebook.
- Try a different Julia version.
- Contact the developers of AbstractPlutoDingetjes.jl about this error.
You might find useful information in the package installation log:
Maybe time for a break? ☕️
👀 Reading hidden code
using AbstractPlutoDingetjes
The package AbstractPlutoDingetjes.jl could not load because it failed to initialize.
That's not nice! Things you could try:
- Restart the notebook.
- Try a different Julia version.
- Contact the developers of AbstractPlutoDingetjes.jl about this error.
You might find useful information in the package installation log:
import AbstractPlutoDingetjes.Bonds.with_js_link
👀 Reading hidden code
The package HypertextLiteral.jl could not load because it failed to initialize.
That's not nice! Things you could try:
- Restart the notebook.
- Try a different Julia version.
- Contact the developers of HypertextLiteral.jl about this error.
You might find useful information in the package installation log:
using HypertextLiteral
👀 Reading hidden code
# let
# messages_to_js = Channel()
# send_to_js(msg) = put!(messages_to_js, msg)
# function get_next_message(_ignore)
# take!(messages_to_js)
# end
# @async begin
# sleep(5)
# for i in 1:10
# send_to_js(i)
# sleep(.3)
# end
# end
# @htl("""
# <script>
# const get_next_msg_from_julia = $(AbstractPlutoDingetjes.Display.with_js_link(get_next_message))
# let running = true
# let messages = async function* () {
# while(running) {
# yield await get_next_msg_from_julia()
# }
# }
# invalidation.then(() => {
# running = false
# })
# for await (const msg of messages()) {
# console.log(msg)
# }
# </script>
# """)
# end
👀 Reading hidden code
1
let
c = Channel(1)
put!(c, 1)
take!(c)
end
👀 Reading hidden code
link_from_julia (generic function with 1 method)
function link_from_julia()
messages_to_js = Channel()
running_ref = Ref{Bool}(true)
function get_next_message(_ignore)
if running_ref[]
# state[] *= "\nwaiting"
# @debug "waiting"
next = take!(messages_to_js)
# @info "done!" next
# state[] *= "\ndone $(next)"
if next === JSGeneratorFinish()
"__jsgen_stop"
else
next
end
else
"__jsgen_stop"
end
end
function stop_generator()
# @debug "stopping"
# state[] *= "\nstopping"
if running_ref[]
running_ref[] = false
# TODO if available
# TODO what if there are multiple clients connected?
put!(messages_to_js, JSGeneratorFinish())
# state[] *= "\nstopped"
end
end
js_generator = JSGenerator(
AbstractPlutoDingetjes.Display.with_js_link(get_next_message, stop_generator),
messages_to_js,
)
return js_generator
end
👀 Reading hidden code
begin
struct JSGeneratorFinish end
struct JSGenerator
APDlink
channel
end
Base.put!(jsg::JSGenerator, msg) = put!(jsg.channel, msg)
function Base.show(io::IO, m::MIME"text/javascript", wjl::JSGenerator)
write(io, """(() => {
let messages = async function* () {
while(true) {
let next = await """)
show(io, m, wjl.APDlink)
write(io, """();
if(next === `__jsgen_stop`) return;
yield next;
}
};
let gen = messages();
invalidation.then(async () => {
console.log("stopping! 1")
gen.return()
console.log("stopping! 2")
});
return gen;
})()""")
end
end
👀 Reading hidden code
""
state = Ref("")
👀 Reading hidden code
# let
# link = link_from_julia()
# @async begin
# sleep(5)
# for i in 1:10
# put!(link, i)
# sleep(.3)
# end
# end
# @htl("""
# <script>
# for await (const msg of $(link)) {
# console.log(msg)
# }
# </script>
# """)
# end
👀 Reading hidden code
state[] |> Text
👀 Reading hidden code
👀 Reading hidden code
syntax: extra token "THIS" after end of expression
Don't panic!
BUT THIS ONLY WORKS FOR ONE CLIENT
WHCIH it should
but right now the messages go "randomly" to one of the clients
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code